<template>
  <div class="mian">
    <el-card style="height: 100%">
      <search-tool @onSearch="handleSearch"></search-tool>
      <el-table
        :data="tableData"
        style="width: 100%"
        height="75%"
        v-loading="loading"
      >
        <el-table-column type="index" width="50" label="序号" />
        <el-table-column prop="equipmentName" label="设备名称" />
        <el-table-column prop="equipmentId" label="设备编号" />
        <el-table-column prop="pipeGallery" label="所属管廊" width="120" />
        <el-table-column prop="warehouse" label="所属仓室" />
        <el-table-column prop="fireCompartment" label="防火分区" />
        <el-table-column prop="specification" label="规格型号" />
        <el-table-column prop="facilitySize" label="设施尺寸" />
        <el-table-column prop="manufacturer" label="生产厂商" />
        <el-table-column prop="handoverTime" label="移交时间" width="180" />
        <el-table-column
          prop="designServiceLife"
          label="设计使用年限"
          width="160"
        />
        <el-table-column prop="ownershipUnit" label="权属单位" />
        <el-table-column prop="constructionUnit" label="施工单位" />
        <el-table-column prop="operationsUnits" label="运维单位" />
        <el-table-column prop="userUnits" label="使用单位" />
        <el-table-column prop="currentState" label="当前状态" width="80">
          <template #default="{ row }">
            <span
              class="state"
              :style="
                row.currentState === '01'
                  ? {
                      background: '#62c654',
                      'box-shadow': '0px 0px 6px 1px #62c654'
                    }
                  : {
                      background: '#dee1e6',
                      'box-shadow': '0px 0px 6px 1px #dee1e6'
                    }
              "
            ></span
            >&nbsp;
            {{ row.currentState === '01' ? '使用中' : '未使用' }}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[5, 10, 20]"
        :page-size="size"
        layout="prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SearchTool from './components/SearchToll/index.vue'
import { assemanagementList } from '@/api/equipment'
const tableData = ref([])
const total = ref(0)
const page = ref(1)
const size = ref(8)
const params = ref({})
const loading = ref(false)
const getListData = (params) => {
  loading.value = true
  assemanagementList(params, page.value, size.value).then((res) => {
    tableData.value = res.rows
    total.value = res.total
  })
  loading.value = false
}

const reloadPage = () => {
  getListData(params.value)
}
reloadPage()

//查询条件相关
const handleSearch = (paramsData) => {
  params.value = paramsData
  getListData(paramsData)
}
// 分页相关
/**
 * size 改变触发
 */
const handleSizeChange = (currentSize) => {
  size.value = currentSize
  getListData(params.value)
}

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  page.value = currentPage
  getListData(params.value)
}
</script>

<style lang="scss" scoped>
.mian {
  width: 100%;
  height: 100%;
  .state {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 10px;
    background: #62c654;
    box-shadow: 0px 0px 6px 1px #35b15c;
    opacity: 1;
  }
  .pagination {
    width: 100%;
    height: 32px;
    margin-top: 30px;
    display: flex;
    align-items: center;
    justify-content: end;
  }
}
</style>
